package com.hue.concurrent.day03;

/*
    sleep和wait的区别：
        sleep是Thread的静态方法，wait是Object的普通方法
        sleep不会释放锁，wait会释放锁
        但是线程的状态一样：TIMED_WAITING
 */
public class Demo02 {
    private static final Object lock = new Object();

    public static void main(String[] args) {
        new Thread(()->{
            synchronized (lock){
                System.out.println("t1拿到lock");
                try {
//                    Thread.sleep(3000);
                    lock.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();

        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        synchronized (lock){
            System.out.println("main线程拿到lock");
            lock.notify();
        }
    }
}
